# ==========================
# ===  General settings  ===
# ==========================

set -g default-terminal "alacritty"
set-option -sa terminal-features ',alacritty:RGB'
set-option -ga terminal-features ",alacritty:usstyle"

set -g history-limit 10000

set -s focus-events on

# Index starts from 1
set -g base-index 1
setw -g pane-base-index 1   # make pane numbering consistent with windows

setw -g automatic-rename on # rename window to reflect current program
set -g renumber-windows on  # renumber windows when a window is closed

set -g set-titles on                        # set terminal title
set -g set-titles-string '#h ❐ #S ● #I #W'

# reduce the time when type prefix
set -s escape-time 0

setw -g monitor-activity on
set -g visual-activity off

set -g repeat-time 400
# ==========================
# ===    Colorscheme     ===
# =========================,bg==

# =====================================
# ===    Appearence and status bar  ===
# ======================================
set -g status-interval 1
set -g status off

# ==========================
# ===   Key bindings     ===
# ==========================
setw -g xterm-keys on
# use vi mode
set -g mode-keys vi
# set prefix key
set -g prefix C-Space
# unbind the default prefix key C-b
unbind C-b
unbind '"'
unbind %
bind i split-window -h -c "#{pane_current_path}"
bind e split-window -v -c "#{pane_current_path}"

# switch window
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# change the window size
bind -r H resize-pane -L 10
bind -r J resize-pane -D 10
bind -r K resize-pane -U 10
bind -r L resize-pane -R 10

# create new window with new name
bind c command-prompt -p "window name:" "new-window; rename-window '%%'"

# reload the tmux config
bind r source-file ~/.config/tmux/tmux.conf \; display "Configuration Reloaded"

# kill panel
bind q kill-window

# debug mode panel
bind m new-window -c "#{pane_current_path}" \;\
       rename-window 'debug' \;\
       split-window -bfh -c "#{pane_current_path}" \;\
       select-pane -D

# toggle status bar
bind s set-option -g status

# ==========================
# ===   Plugin Resurrect ===
# ==========================

# tmux-resurrect
set -g @resurrect-capture-pane-contents 'on'
# save vim session
set -g @resurrect-strategy-vim 'session'
# save neovim session
set -g @resurrect-strategy-nvim 'session'

# ============================
# ===       Plugins        ===
# ============================
set-environment -g TMUX_PLUGIN_MANAGER_PATH '~/.local/share/tmux'
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @prefix_highlight_show_copy_mode 'on'
set -g @prefix_highlight_copy_mode_attr 'fg=white,bg=blue'
set -g @continuum-save-interval '15'

run '~/.local/share/tmux/tpm/tpm'
